import { ajax } from '../libs/ajax.js';

let txt_username = document.getElementById('txt_username');
let txt_password = document.getElementById('txt_password');
let btnLogin = document.getElementById('btnLogin');
let spLogin = document.getElementById('spLogin');

btnLogin.addEventListener('click', () => {
  spLogin.innerHTML = '';
  let user = {
    username: txt_username.value,
    password: txt_password.value,
  };
  ajax.post('/auth', user, (data) => {
    spLogin.innerHTML = data.message;
    // 如果登录成功跳转到首页
    if(data.success){
      location.href = 'main.html';
    }
  });
});
